<template>
	<view class="greyBox padBottom_130">
		<view class="orderTopBlock"
			style="background: url(https://supply.zhongyimotor.com/upload/applet/bg_order_supplier@2x.png) 0 0 no-repeat;background-size: 100%;">
			<view class="title">
				<view class="icon">
					<u-icon name="https://supply.zhongyimotor.com/upload/applet/icon_audit_wait_supplier@2x.png"
						size="32"></u-icon>
				</view>
				{{salesTableType[details.sellerCarInApply.status].label}}
			</view>
			<view class="summary" v-if="details.sellerCarInApply.status != 8">请耐心等待~</view>
		</view>
		<view class="details">
			<view class="item">
				<view class="top ">
					<view class="title ">借款银行</view>
					<view class="data">{{details.sellerCarInApply.bankName}}</view>
				</view>
			</view>
			<view class="item">
				<view class="top ">
					<view class="title ">仓库基本信息</view>
				</view>
				<view class="content">
					<view class="dataCell">
						<view class="title">仓库名称</view>
						<view class="data">{{details.storeInfo.name}}</view>
					</view>
					<view class="dataCell">
						<view class="title">仓库地址</view>
						<view class="data">{{details.storeInfo.addressDetails}}</view>
					</view>
					<view class="dataCell">
						<view class="title">联系人</view>
						<view class="data">{{details.storeInfo.contactPerson}}</view>
					</view>
					<view class="dataCell">
						<view class="title">联系方式</view>
						<view class="data">{{details.storeInfo.contactPhone}}</view>
					</view>
				</view>
			</view>
			<view class="item ">
				<view class="top">
					<view class="title">车辆基本信息</view>
					<view class="right" @click="carsListPopup = true">全部<u-icon name="arrow-right"></u-icon></view>
				</view>
				<view class="content">
					<view class="infoItem" v-for="(item,index) in details.carListDetailsList" :key="index"
						v-if="index <= 2">
						<view class="infoCell">
							<view class="title">
								<view class="titleContent">
									{{item.brand}} {{item.series}} {{item.model}}
								</view>
							</view>
							<view class="data">￥{{item.price}}</view>
						</view>
						<view class="infoCell">
							<view class="title tiny grey">
								<view class="icon">
									<u-icon name="https://supply.zhongyimotor.com/upload/applet/pic_car_supplier@2x.png"
										size="32"></u-icon>
								</view>
								<view class="">
									<view v-for="(vin,i) in item.vinsList" :key="i">车架号：{{vin}}</view>
								</view>
							</view>
							<view class="data grey">x {{item.vinsList.length}}</view>
						</view>
					</view>
				</view>
				<view class="bottom">
					<view class="totalPrice right">
						<view class="carNum">共计{{totalCarNum}}台</view>
						<view class="price">
							<view class="">合计：</view>
							<view class="priceNum">¥ {{totalPrice}}</view>
						</view>
					</view>
				</view>
			</view>
			<view class="item" v-if="details.contractList && details.contractList.length > 0">
				<view class="top ">
					<view class="title ">合同</view>
				</view>
				<view class="content">
					<view class="dataCell" v-if="contractTempList.length > 0">
						<view class="title">合同模板</view>
					</view>
					<view class="infoItem" v-for="(item,index) in contractTempList" :key="index">
						<view class="infoCell">
							<view class="title grey">{{item.contractName}}</view>
							<view class="data" @click="openFile(item.url)">
								<u-icon
									name="https://supply.zhongyimotor.com/upload/applet/icon_contract2_supplier@2x.png"
									size="32"></u-icon>
							</view>
						</view>
					</view>
					<view class="dataCell" v-if="contractList.length > 0">
						<view class="title">已上传合同</view>
					</view>
					<view class="infoItem" v-for="(item,index) in contractList" :key="index">
						<view class="infoCell">
							<view class="title grey">{{item.contractName}}</view>
							<view class="data" @click="openFile(item.url)">
								<u-icon
									name="https://supply.zhongyimotor.com/upload/applet/icon_contract2_supplier@2x.png"
									size="32"></u-icon>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="item" v-if="details.earnestMoneyInfo">
				<view class="top ">
					<view class="title ">支付金额信息</view>
					<view class="right" @click="costListPopup = true">明细<u-icon name="arrow-right"></u-icon></view>
				</view>
				<view class="content">
					<view class="dataCell">
						<view class="title">保证金</view>
						<view class="data fontNum">¥ {{details.earnestMoneyInfo.amount}}</view>
						<view class="sub">
							<text>*</text>
							保证金金额=车辆价格*保证金比例
						</view>
					</view>
				</view>
			</view>
		</view>
		<u-popup v-model="carsListPopup" mode="bottom" :closeable="true">
			<carsInfoList ref="carsInfoList" :list="details.carListDetailsList" :totalPrice="totalPrice"
				:totalCarNum="totalCarNum"></carsInfoList>
		</u-popup>
		<u-popup v-model="costListPopup" mode="bottom" :closeable="true">
			<costList ref="costList" :list="details.carListDetailsList" :totalDeposit="details.earnestMoneyInfo.amount">
			</costList>
		</u-popup>
		<u-toast ref="uToast" />
		<u-no-network></u-no-network>
	</view>
</template>

<script>
	import {
		openFile
	} from '@/utils/index.js';
	import {
		salesTableType
	} from '@/utils/status.js';
	import carsInfoList from '@/components/carsInfoList.vue';
	import costList from '@/components/costList.vue';
	import moment from "moment";
	export default {
		components: {
			carsInfoList,
			costList
		},
		data() {
			return {
				salesTableType,
				carsListPopup: false,
				costListPopup: false,
				details: {
					carListDetailsList: []
				},
				totalCarNum: 0,
				totalPrice: 0,
				contractTempList: [],
				contractList: [],
			}
		},
		onLoad(option) {
			this.getDetails(option.id)
		},
		onShow() {
			let that = this
		},
		onBackPress() {

		},
		methods: {
			openFile,
			getDetails(id) {
				let that = this;
				let params = {
					id
				}
				that.$api.getSalesDetails(params).then(res => {
					that.details = res.result;
					that.details.carListDetailsList.forEach(item => { //拆分车架号数组
						item.vinsList = item.vin.split(",");
						that.totalCarNum = that.totalCarNum + item.vinsList.length;
						that.totalPrice = that.totalPrice + item.totalPrice;
					})

					that.details.contractList.forEach(item => {
						if (item.type == 0) {
							that.contractTempList.push(item)
						} else {
							that.contractList.push(item)
						}
					})
					that.details.earnestMoneyInfo = res.result.sellerBill.find((x) => {
						return x.type === 1;
					});
				})
			}
		}
	};
</script>

<style scoped lang="scss">
	.totalPrice {
		display: flex;
		height: 100rpx;

		line-height: 100rpx;
		background: #FFF;

		&.right {
			justify-content: flex-end;
		}

		.carNum {
			font-size: 24rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 400;
			color: #878787;
			margin-right: 20rpx;
		}

		.price {
			font-size: 24rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 400;
			color: #202020;
			display: flex;

			.priceNum {
				font-size: 28rpx;
				font-family: DINAlternate, DINAlternate;
				font-weight: bold;
				color: #F76260;
			}
		}
	}
</style>